﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>3.静态函数Configure的使用</title>
	<script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
	<script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
	<link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
	<script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
	<h3>3.静态函数Configure的使用</h3>
	<p>
		<b>1.定义接口和类型</b><br />
		<pre class="brush: csharp">
		public interface IAnimal
		{
			void Talk();
		}
		public class Dog : IAnimal
		{
			public NFinal.IO.IWriter writer;
			public Dog(NFinal.IO.IWriter writer)
			{
				this.writer=writer;
			}
			public void Talk()
			{
				this.writer.Write("我是一只小小狗");
				this.writer.Writer("<br/>"):
			}
		}
        </pre>
	</p>
	<p>
		<b>2.在Startup函数中进行注入</b><br />
		<pre class="brush: csharp">
		public class Startup
		{
			public void Configuration(IAppBuilder appBuilder)
			{
				NFinal.Config.Configration.serviceCollection.Set&lt;IAnimal,NFinal.IO.IWriter>(typeof(Dog));
				appBuilder.Use&lt;NFinal.Middleware.OwinMiddleware>();
				appBuilder.UseStaticFiles();
			}
		}
		</pre>
	</p>
	<p>
		<b>3.在Controller控制器中使用</b><br />
		<pre class="brush: csharp">
		public class IndexController : BaseController
		{
			public void Index()
			{
				IAnimal animal = NFinal.Config.Configration.serviceCollection.Get&lt;IAnimal>(this);
				//该控制器会输出:我是一只小小狗
				animal.Talk();
			}
		}
		</pre>
	</p>
</body>
</html>
